(defun p1uxtar-font-lock-function-name-when-prog ()
  "Use large font for function name when programming."
  (face-remap-add-relative 'font-lock-function-name-face :height 150))

(add-hook 'prog-mode-hook
	      (lambda ()
	        (linum-mode -1)
	        (p1uxtar-font-lock-function-name-when-prog)))

;; -------- update prog-mode config --------
(use-package aggressive-indent
  :diminish aggressive-indent-mode
  :hook
  ((prog-mode) . aggressive-indent-mode)
  :config
  (dolist (hook (list
                 'artist-mode-hook
                 'python-mode-hook
                 'separedit-mode-hook
                 ))
    (add-hook hook (lambda ()
                     (aggressive-indent-mode -1)))))

;; -------- awesome-pair --------
(use-package awesome-pair
  :load-path "lazycat-bucket/awesome-pair"
  :hook
  ((c-mode c++-mode cperl-mode emacs-lisp-mode js-mode lisp-interaction-mode markdown-mode org-mode python-mode sh-mode yaml-mode) . awesome-pair-mode)
  :bind
  (("(" . 'awesome-pair-open-round)
   ("[" . 'awesome-pair-open-bracket)
   ("{" . 'awesome-pair-open-curly)
   (")" . 'awesome-pair-close-round)
   ("]" . 'awesome-pair-close-bracket)
   ("}" . 'awesome-pair-close-curly)
   ("=" . 'awesome-pair-equal)
   ("%" . 'awesome-pair-match-paren)
   ("\"" . 'awesome-pair-double-quote)
   ("SPC" . 'awesome-pair-space)
   ("C-h" . 'awesome-pair-backward-delete)
   ("C-d" . 'awesome-pair-forward-delete)
   ("C-k" . 'awesome-pair-kill)
   ("M-\"" . 'awesome-pair-wrap-double-quote)
   ("M-[" . 'awesome-pair-wrap-bracket)
   ("M-{" . 'awesome-pair-wrap-curly)
   ("M-(" . 'awesome-pair-wrap-round)
   ("M-s" . 'awesome-pair-unwrap)
   ("C-M-f" . 'awesome-pair-jump-right)
   ("C-M-b" . 'awesome-pair-jump-left)
   ("C-<return>" . 'awesome-pair-jump-out-pair-and-newline)))

;; -------- electric-operator --------
(use-package electric-operator)

;; -------- syntax checking --------
(use-package flycheck
  :defer t
  :diminish flycheck-mode
  :hook
  (prog-mode . flycheck-mode)
  :config
  (global-flycheck-mode -1)
  (use-package flycheck-posframe
    :ensure t
    :if window-system
    :after flycheck
    :config
    (add-hook 'flycheck-mode-hook #'flycheck-posframe-mode)
    (setq flycheck-posframe-position 'window-bottom-left-corner)))

;; -------- format code & prettier --------
(when (string-equal system-type "gnu/linux")
  (use-package format-all
    :diminish format-all-mode
    ;; :hook
    ;; ((prog-mode) . format-all-mode)
    :config
    (format-all-mode)
    :bind
    (("C-S-f" . 'format-all-buffer))))
;; (use-package prettier
;;   :init
;;   (setenv "NODE_PATH" "/usr/lib/node_modules")
;;   :hook
;;   ((after-init) . global-prettier-mode)
;;   :config
;;   (defun p1uxtar-prettier ()
;;     (interactive)
;;     (shell-command
;;      (format "%s --write %s"
;; 	       (shell-quote-argument (executable-find "prettier"))
;; 	       (shell-quote-argument (expand-file-name buffer-file-name))))
;;     (revert-buffer t t t))
;;   (add-hook 'markdown-mode-hook
;; 	      (lambda ()
;; 		(add-hook 'after-save-hook 'p1uxtar-prettier t t))))
;; (use-package shfmt
;;   :config
;;   (add-hook 'sh-mode-hook 'shfmt-on-save-mode))

;; ;; -------- highlight-indentation --------
(use-package highlight-indentation
  :diminish highlight-indentation-mode
  :hook
  ((prog-mode) . highlight-indentation-mode))

;; ;; -------- highlight-indent-guides --------
;; (use-package highlight-indent-guides
;;   :diminish highlight-indent-guides-mode
;;   :hook
;;   ((prog-mode) . highlight-indent-guides-mode)
;;   :init
;;   (setq highlight-indent-guides-method 'column
;; 	    highlight-indent-guides-auto-enabled t
;; 	    highlight-indent-guides-responsive 'top))

;; -------- highlight numeric literals in source code --------
(use-package highlight-numbers
  :ensure t
  :hook
  ((prog-mode) . highlight-numbers-mode))

;; -------- display relative line number --------
(use-package linum-relative
  :ensure t
  :config
  (setq linum-relative-backend 'display-line-numbers-mode))

;; -------- highlight delimiters such as (), [] or {} --------
(use-package rainbow-delimiters
  :defer t
  :diminish rainbow-delimiters-mode
  :hook
  (((prog-mode) . rainbow-delimiters-mode)
   ((rainbow-delimiters-mode . show-paren-mode))))

;; -------- symbol-overlay --------
(use-package symbol-overlay
  :defer t
  :diminish symbol-overlay-mode
  :hook
  ((prog-mode) . symbol-overlay-mode)
  :bind
  (("M-i" . 'symbol-overlay-put)
   ("M-n" . 'symbol-overlay-jump-next)
   ("M-p" . 'symbol-overlay-jump-prev)
   ("M-I" . 'symbol-overlay-remove-all)
   ("C-M-r" . 'symbol-overlay-query-replace)))

(provide '+prog)
